import request from '../../../../utils/request'
Page({
  data: {
    servicePac: [],
    jigouid: '',
    tags:[
      {name: '基础医疗', class: 'tag-blue' },
      { name: '儿童护理', class: 'tag-yellow' },
      { name: '慢病管理', class: 'tag-green' }
    ],
    jigou: {},
    // servicePac:[],
    institution: {
      name: '北京市怀柔区洛西社区卫生服务站',
      address: '怀柔区洛西县建设路990号',
      description: '始建于1994年10月，是清新地区唯一一所集医疗、教学、科研、保健为一体的国家二级甲等非营利性综合医疗机构，承担着本区群众的医疗救治、预防保健和康复、健康教育、医学科研教学等工作任务，先后荣获清新区"创建国家慢性病综合防控示范区先进单位"。'
    },
    teams: [{
        id: 1,
        name: '王天戈团队',
        location: '翡翠郡社区服务站',
        distance: '4.9',
        rating: 4,
        avatar: '/assets/images/team-avatar.png'
      },
      {
        id: 2,
        name: '王天戈团队',
        location: '翡翠郡社区服务站',
        distance: '4.9',
        rating: 4,
        avatar: '/assets/images/team-avatar.png'
      },
      {
        id: 3,
        name: '王天戈团队',
        location: '翡翠郡社区服务站',
        distance: '4.9',
        rating: 4,
        avatar: '/assets/images/team-avatar.png'
      }
    ]
  },

  onLoad(options) {
    // 可以通过options.id获取机构ID，加载具体数据
    //console.log(options.id)
    this.setData({
      jigouid: options.id
    })
    this.getjigou();
    this.getTeam();
    this.getServicePac();
  },

  onLocationTap() {
    // 打开地图
    wx.openLocation({
      latitude: 40.123456, // 需要替换为实际经纬度
      longitude: 116.123456,
      name: this.data.institution.name,
      address: this.data.institution.address
    });
  },

  onPhoneCall() {
    wx.makePhoneCall({
      phoneNumber: this.data.jigou.phone // 需要替换为实际电话号码
    });
  },

  onMessage() {
    // 处理消息按钮点击
    wx.showToast({
      title: '功能开发中',
      icon: 'none'
    });
  },
  getjigou() {
    request({
      url: 'system/institution/' + this.data.jigouid,
      method: 'GET',
      success: (result) => {
        console.log(result.data.data)
        this.setData({
          jigou: result.data.data
        })
      },
      fail: (err) => {},
      complete: (res) => {},
    })
  },
  getTeam() {
    request({
      url: 'system/team/list',
      method: "GET",
      data: {
        institutionid: this.data.jigouid
      },
      success: (result) => {
        console.log(result.data.rows)
        this.setData({
          teams: result.data.rows
        })
      },
      fail: (err) => {},
      complete: (res) => {},
    })
  },
  getServicePac() {
    request({
      url: 'package/package/list',
      method: "GET",
      success: (result) => {
        console.log(result.data.rows);
        this.setData({
          servicePac: result.data.rows
        });

      },
      fail: (err) => {
        console.error('获取服务包失败', err);
        wx.showToast({
          title: '获取服务包失败',
          icon: 'none'
        });
      }
    });
  },
  onTeamClick(e) {
    let id= e.currentTarget.dataset.id;
    wx.navigateTo({
      // ../nearbyTeams/teamDetail/teamDetail?id=
      url: '../../nearbyTeams/teamDetail/teamDetail?id=' + id
    });
  },
  onServiceClick(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      //serviceDetail/serviceDetail?id=${id}
      url: `/pages/index/nearbyTeams/serviceDetail/serviceDetail?id=${id}`
    });
  }
});